package Homework.apiDay04;

import java.io.File;
import java.io.IOException;

public class FileDemo {
    public static void main(String[] args) throws IOException {
        File file = new File("./test.txt");
        System.out.println("是否存在:" + file.exists() + ",名字:"+file.getName() + ",路径:"+file.getPath()
                        +"绝对路径:"+file.getAbsolutePath()+"\n路径:"+file.getCanonicalPath()+"\n大小:"
                        +file.length()+",写:"+file.canWrite()+"读:"+file.canRead()+"\n是否目录"+file.isDirectory()
                        +",是否文件:"+file.isFile()
                );
        if(file.exists()){
            if(file.delete())
            System.out.println("删除成功");
        }else{
            if(file.createNewFile()){
                System.out.println("创建成功");
            }
        }

        File file1 = new File("./test");
        System.out.println("是否存在:" + file1.exists() + ",名字:"+file1.getName() + ",路径:"+file1.getPath()
                +"绝对路径:"+file1.getAbsolutePath()+"\n路径:"+file1.getCanonicalPath()+"\n大小:"
                +file1.length()+",写:"+file1.canWrite()+"读:"+file1.canRead()+"\n是否目录"+file1.isDirectory()
                +",是否文件:"+file1.isFile()
        );
        if(file1.exists()){
            if(file1.delete())
                System.out.println("删除成功");
        }else{
            if(file1.mkdir()){
                System.out.println("创建成功");
            }
        }
    }
}
